import React from 'react';

import Loadable from 'react-loadable';

import Loading from '../components/common/pageLoader';

export default function lazyLoader(loader) {
  return Loadable({
    delay: 300,
    timeout: 5000,
    loader,
    loading: (props) => {
      let view = null;
      if (props.error) {
        view = <Loading type="error" retry={props.retry} />;
      } else if (props.timedOut) {
        view = <Loading type="timeout" retry={props.retry} />;
      } else if (props.pastDelay) {
        view = <Loading type="loading" retry={props.retry} />;
      }
      return view;
    },
  });
}
